package finance

import grails.test.*

class SessionRunIntegrationTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testSessionRunCreation() {
		def simulation = new Simulation(name : "sim1", description : " first test").save()
		def session = new Session(description : "First session")
		
		def run1 = new SessionRun()
		def param1 = new StrategyParameter( name : "param1", 
			description : "first parameter", val : "1.0")
		run1.addToParameters( param1 )
		session.addToRuns( run1 )
		assertEquals 1, session.runs.size()
		
		def run2 = new SessionRun()
		def param2 = new StrategyParameter( name : "param2", 
			description : "second parameter", val : "2.0")
		run2.addToParameters( param2 )
		session.addToRuns( run2 )
		assertEquals 2, session.runs.size()
	
		simulation.addToSessions( session )
		
		assertEquals ([ 'param1' , 'param2' ],	
			simulation.sessions.runs.parameters*.name.flatten().sort())
		
		def foundSimulation = Simulation.get(simulation.id)
		assertEquals ([ 'param1' , 'param2' ],	
			foundSimulation.sessions.runs.parameters*.name.flatten().sort())
    }
}
